package main

import "log"

/*抽象工厂模式*/
func main() {
	var factory AbstractFactory
	factory = new(Factory)
	fruits := factory.GetFruits("apple").NewFruits()
	log.Println(fruits)

	vegetables := factory.GetVegetables("potato").NewVegetables()
	log.Println(vegetables)
}

type Factory struct{}

func (f *Factory) GetFruits(need string) Fruits {
	switch need {
	case "apple":
		return new(Apple)
	case "orange":
		return new(Orange)
	}
	return nil
}

func (f *Factory) GetVegetables(need string) Vegetables {
	switch need {
	case "potato":
		return new(Potato)
	case "eggplant":
		return new(Eggplant)
	}
	return nil
}

type AbstractFactory interface {
	GetFruits(need string) Fruits
	GetVegetables(need string) Vegetables
}

/*水果*/
type Fruits interface {
	NewFruits() string
}

type Apple struct {
}

func (f *Apple) NewFruits() string {
	return "苹果"
}

type Orange struct {
}

func (f *Orange) NewFruits() string {
	return "橘子"
}

/*蔬菜*/
type Vegetables interface {
	NewVegetables() string
}

type Potato struct {
}

func (f *Potato) NewVegetables() string {
	return "土豆"
}

type Eggplant struct {
}

func (f *Eggplant) NewVegetables() string {
	return "茄子"
}
